In questo notebook è stato preso un dataset sui laptop e le loro specifiche tecniche da kaddle. Questo dataset possiede 1303 righe ed ognuna di esse è un laptop differente. Ogni colonna invece è una specifica del laptop. Con questo dataset si possono fare varie comparazioni ed analisi interessanti, alcune delle quali esposte di seguito. Tra le analisi più interessanti vi sono: analisi sui sistemi operativi più usati, quantità di laptops per categoria, analisi sulla distribuzione dei prezzi dei laptops per modello di CPU e GPU e distribuzione prezzi per sistema operativo montato.
import numpy as np
np.set_printoptions(precision=2)
import plotly.express as px
import plotly.graph_objs as go
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
laptops = pd.read_csv('data/project/laptop_price.csv', encoding = "latin")
laptops
| laptop_ID | Company | Product | TypeName | Inches | ScreenResolution | Cpu | Ram | Memory | Gpu | OpSys | Weight | Price_euros | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | Apple | MacBook Pro | Ultrabook | 13.3 | IPS Panel Retina Display 2560x1600 | Intel Core i5 2.3GHz | 8GB | 128GB SSD | Intel Iris Plus Graphics 640 | macOS | 1.37kg | 1339.69 |
| 1 | 2 | Apple | Macbook Air | Ultrabook | 13.3 | 1440x900 | Intel Core i5 1.8GHz | 8GB | 128GB Flash Storage | Intel HD Graphics 6000 | macOS | 1.34kg | 898.94 |
| 2 | 3 | HP | 250 G6 | Notebook | 15.6 | Full HD 1920x1080 | Intel Core i5 7200U 2.5GHz | 8GB | 256GB SSD | Intel HD Graphics 620 | No OS | 1.86kg | 575.00 |
| 3 | 4 | Apple | MacBook Pro | Ultrabook | 15.4 | IPS Panel Retina Display 2880x1800 | Intel Core i7 2.7GHz | 16GB | 512GB SSD | AMD Radeon Pro 455 | macOS | 1.83kg | 2537.45 |
| 4 | 5 | Apple | MacBook Pro | Ultrabook | 13.3 | IPS Panel Retina Display 2560x1600 | Intel Core i5 3.1GHz | 8GB | 256GB SSD | Intel Iris Plus Graphics 650 | macOS | 1.37kg | 1803.60 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1298 | 1316 | Lenovo | Yoga 500-14ISK | 2 in 1 Convertible | 14.0 | IPS Panel Full HD / Touchscreen 1920x1080 | Intel Core i7 6500U 2.5GHz | 4GB | 128GB SSD | Intel HD Graphics 520 | Windows 10 | 1.8kg | 638.00 |
| 1299 | 1317 | Lenovo | Yoga 900-13ISK | 2 in 1 Convertible | 13.3 | IPS Panel Quad HD+ / Touchscreen 3200x1800 | Intel Core i7 6500U 2.5GHz | 16GB | 512GB SSD | Intel HD Graphics 520 | Windows 10 | 1.3kg | 1499.00 |
| 1300 | 1318 | Lenovo | IdeaPad 100S-14IBR | Notebook | 14.0 | 1366x768 | Intel Celeron Dual Core N3050 1.6GHz | 2GB | 64GB Flash Storage | Intel HD Graphics | Windows 10 | 1.5kg | 229.00 |
| 1301 | 1319 | HP | 15-AC110nv (i7-6500U/6GB/1TB/Radeon | Notebook | 15.6 | 1366x768 | Intel Core i7 6500U 2.5GHz | 6GB | 1TB HDD | AMD Radeon R5 M330 | Windows 10 | 2.19kg | 764.00 |
| 1302 | 1320 | Asus | X553SA-XX031T (N3050/4GB/500GB/W10) | Notebook | 15.6 | 1366x768 | Intel Celeron Dual Core N3050 1.6GHz | 4GB | 500GB HDD | Intel HD Graphics | Windows 10 | 2.2kg | 369.00 |
1303 rows × 13 columns
laptops['Main_Memory'] = laptops['Memory'].str.split("+").str[0]
laptops['Secondary_Memory'] = laptops['Memory'].str.split("+").str[1]
laptops['Main_Memory'] = laptops['Main_Memory'].str.strip()
laptops['Main_Memory_Type'] = laptops['Main_Memory'].str.split(" ").str[1:]
laptops['Main_Memory'] = laptops['Main_Memory'].str.split(" ").str[0]
laptops['Main_Memory_Type'] = laptops['Main_Memory_Type'].str.join(" ")
laptops['Operating_System'] = laptops['OpSys'].replace({'Windows 10' : 'Windows', 'Windows 10 S' : 'Windows', 'Windows 7' : 'Windows', 'Mac OS X' : 'Mac OS', 'macOS' : 'Mac OS' })
res=laptops['ScreenResolution'].str.split('x',n=1,expand=True)
#Creare colonna con nomi di tutte le CPU
laptops['Cpu_Name']=laptops['Cpu'].apply(lambda x:" ".join(x.split()[0:3]))
#Divide per categoria
def divisore(text):
if text == 'Intel Core i7' or text == 'Intel Core i5' or text == 'Intel Core i3':
return text
else:
if text.split()[0] == 'Intel':
return 'Other Intel Processor'
else:
return 'AMD Processor'
laptops['Brand_CPU']=laptops['Cpu_Name'].apply(divisore)
laptops['TouchScreen']=laptops['ScreenResolution'].apply(lambda x:1 if 'Touchscreen' in x else 0)
laptops['IPS']=laptops['ScreenResolution'].apply(lambda x:1 if'IPS' in x else 0)
laptops['Brand_GPU'] = laptops['Gpu'].apply(lambda x:x.split()[0])
fig = px.pie(laptops, values=laptops['Price_euros'], names=laptops['Operating_System'])
fig.show()
#Quantità laptops realizzati per produttore
fig = px.histogram(laptops['Company']).update_xaxes(categoryorder = 'total descending')
fig.update_layout(
title ='Quantità laptops realizzati per produttore',
xaxis_title = 'Produttori',
yaxis_title = 'Quantità di pc',
legend_title = 'Produttore'
)
fig.show()
#Quantità laptops per categoria
fig = px.histogram(laptops['TypeName'])
fig.update_xaxes(categoryorder = 'total descending')
fig.update_layout(
title ='Quantità laptops per categoria',
xaxis_title = 'Categoria',
yaxis_title = 'Quantità di pc'
)
fig.show()
#Quantità laptops dei produttori per categoria
tmp = laptops.copy()
tmpMask = (tmp["Company"] != "Dell") & (tmp["Company"] != "Lenovo") & (tmp["Company"] != "HP") & (tmp["Company"] != "Asus") & (tmp["Company"] != "Acer")
tmp.loc[tmpMask, "Company"] = "Altro"
fig = px.histogram(tmp, x='TypeName', color='Company')
fig.update_xaxes(categoryorder = 'total descending')
fig.update_layout(
title ='Quantità laptops dei produttori per categoria',
xaxis_title = 'Categoria',
yaxis_title = 'Quantità di pc',
legend_traceorder="reversed",
legend_title = 'Produttore'
)
fig.show()
#Numero di computer per ogni CPU
fig = px.histogram(laptops['Brand_CPU'])
fig.update_xaxes(categoryorder = 'total descending')
fig.update_layout(
title ='Quantità laptops per ogni modello CPU',
xaxis_title = 'Modello CPU',
yaxis_title = 'Quantità di pc'
)
fig.show()
#Distribuzione prezzi per tipo di CPU
fig = px.histogram(laptops, x=laptops['Brand_CPU'],y=laptops['Price_euros'], histfunc='avg')
fig.update_xaxes(categoryorder = 'array', categoryarray=['Intel Core i7', 'Intel Core i5', 'Other Intel Processor', 'Intel Core i3', 'AMD Processor'])
fig.update_layout(
title ='Distribuzione prezzi dei laptops per modello di CPU',
xaxis_title = 'Modello CPU',
yaxis_title = 'Prezzo medio dei laptops [€]'
)
fig.show()
#Prezzi laptops per CPU montata
fig = go.Figure(data=go.Heatmap(
z=laptops['Price_euros'],
x=laptops['Brand_CPU'],
y=laptops['Operating_System'],
hoverongaps = False))
fig.update_layout(
title ='Prezzi laptops per CPU montata',
xaxis_title = 'Modello CPU',
yaxis_title = 'Sistema Operativo'
)
fig.show()
#Quantità laptops per ogni modello GPU
fig = px.histogram(laptops['Brand_GPU'])
fig.update_xaxes(categoryorder = 'total descending')
fig.update_layout(
title ='Quantità laptops per ogni modello GPU',
xaxis_title = 'Modello GPU',
yaxis_title = 'Quantità di pc'
)
fig.show()
#Distribuzione prezzi dei laptops per modello di GPU
fig = px.histogram(laptops, x=laptops['Brand_GPU'],y=laptops['Price_euros'], histfunc='avg')
fig.update_xaxes(categoryorder = 'array', categoryarray=['Intel', 'Nvidia', 'AMD', 'ARM'])
fig.update_layout(
title ='Distribuzione prezzi dei laptops per modello di GPU',
xaxis_title = 'Modello GPU',
yaxis_title = 'Prezzo medio dei laptops [€]'
)
fig.show()
#Prezzi laptops per GPU montata
fig = go.Figure(data=go.Heatmap(
z=laptops['Price_euros'],
x=laptops['Brand_GPU'],
y=laptops['Operating_System'],
hoverongaps = False))
fig.update_layout(
title ='Prezzi laptops per GPU montata',
xaxis_title = 'Modello GPU',
yaxis_title = 'Sistema Operativo'
)
fig.show()
#Costo laptops per sistema operativo
fig = px.box(laptops, x=laptops['Price_euros'],y=laptops['Operating_System'], orientation="h")
fig.update_layout(
title ='Costo laptops per sistema operativo',
xaxis_title = 'Prezzo per unità',
yaxis_title = 'Sistema Operativo'
)
fig.show()
#Distribuzione prezzi per sistema operativo
fig = px.histogram(laptops, x=laptops['Price_euros'], color='Operating_System')
fig.update_layout(
title ='Distribuzione prezzi per sistema operativo',
xaxis_title = 'Prezzo per unità',
yaxis_title = 'Quantità di pc',
legend_title = 'Sistema Operativo'
)
fig.show()
#Quantità laptops dei sistemi operativi per categoria (NO WINDOWS)
#È stato esscluso windows dalle analisi in quanto avrebbe falsato il risultato essendo il sistema operativo più comune in assoluto.
tmp = tmp.drop(tmp[tmp.Operating_System == "Windows"].index)
fig = px.histogram(tmp, x='TypeName', color='Operating_System')
fig.update_xaxes(categoryorder = 'total descending')
fig.update_layout(
title ='Quantità laptops dei sistemi operativi per categoria (NO WINDOWS)',
xaxis_title = 'Categoria',
yaxis_title = 'Quantità di pc',
legend_traceorder="reversed",
legend_title = 'Sistema Operativo'
)
fig.show()
#Diffusione delle tipologie di memoria nelle varie fascie di prezzo
fig = plt.figure(figsize=(10,5))
ax = plt.axes()
fig.patch.set_facecolor("#FFFFFF")
ax.set_facecolor("#FFFFFF")
ax.set(xlabel='Prezzo per unità [€]', ylabel='Densità')
sns.kdeplot(data=laptops, x="Price_euros", hue="Main_Memory_Type",multiple="fill",palette="pastel");
plt.text(-800,1.3,"Diffusione delle tipologie di memoria nelle varie fascie di prezzo", {"font":"Arial", "weight":"bold", "size":12.5});
plt.legend(labels=["Ibrido", "HDD", "Flash", "SSD"], title = "Tipo di memoria")
<matplotlib.legend.Legend at 0x2192d1c7a90>